﻿using System;
using Riba.MVVMSL;

namespace MVVMtutorial
{
	public class Dialog3ViewModel : ViewModelBase
	{
		private Type _currentViewType;
		public RelayCommand CommandBack { get; private set; }
		public RelayCommand CommandForward { get; private set; }

		public Dialog3ViewModel()
		{
			CommandBack = new RelayCommand(OnNavigateBack);
			CommandForward = new RelayCommand(OnNavigateForward);

			NavigatorLoaded += Dialog3ViewModel_NavigatorLoaded;
		}

		void Dialog3ViewModel_NavigatorLoaded(object sender, EventArgs e)
		{
			CommandForward.Execute(null);

			CommandBack.IsEnabled = true;
			CommandForward.IsEnabled = true;
		}

		private void OnNavigateBack(object handler)
		{
			_currentViewType = _currentViewType == typeof(Wizard1) ? typeof(Wizard2) : typeof(Wizard1);

			RaiseNavigateToView(new NavigateToViewEventArgs(_currentViewType, AnimationMode.Backward));
		}

		private void OnNavigateForward(object handler)
		{
			_currentViewType = _currentViewType == typeof(Wizard1) ? typeof(Wizard2) : typeof(Wizard1);
			RaiseNavigateToView(new NavigateToViewEventArgs(_currentViewType, AnimationMode.Forward));
		}
	}
}
